// src/api/vpn.js
import request from '@/utils/request'

// 节点相关API
export const getNodes = () => {
    return request.get('/nodes')
}

export const switchNode = (userSubscriptionId, nodeId) => {
    return request.put(`/user-subscriptions/${userSubscriptionId}/switch-node`, { node_id: nodeId })
}

// 用户订阅相关API
export const getUserSubscriptions = (userId) => {
    return request.get(`/user-subscriptions/user/${userId}`)
}

export const createUserSubscription = (data) => {
    return request.post('/user-subscriptions', data)
}

export const renewSubscription = (userSubscriptionId) => {
    return request.post(`/user-subscriptions/${userSubscriptionId}/renew`)
}

// WireGuard配置相关API
export const downloadWireGuardConfig = (userSubscriptionId) => {
    return request.get(`/wireguard/config/${userSubscriptionId}/download`, {
        responseType: 'blob'
    })
}

export const getWireGuardConfig = (userSubscriptionId) => {
    return request.get(`/wireguard/config/${userSubscriptionId}`)
}

export const refreshWireGuardConfig = (userSubscriptionId) => {
    return request.post(`/wireguard/config/${userSubscriptionId}/refresh`)
}

// 订阅套餐相关API
export const getSubscriptions = () => {
    return request.get('/subscription/')
}

export const createSubscription = (data) => {
    return request.post('/subscription/', data)
}

export const updateSubscription = (subId, data) => {
    return request.patch(`/subscription/${subId}`, data)
}

export const purchaseSubscription = (data) => {
    return request.post('/subscription/purchase', data)
}

// 使用记录相关API
export const getUsageHistory = (userId, params = {}) => {
    return request.get(`/usage-history/user/${userId}`, { params })
}

// 用户管理API
export const getUsers = () => {
    return request.get('/users/')
}

export const getUser = (userId) => {
    return request.get(`/users/${userId}`)
}

export const deleteUser = (userId) => {
    return request.delete(`/users/${userId}`)
}